package com.dtf.admin.base;

import java.io.IOException;
import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class BaseForm {

	private int pageNum = 1;
	/**
	 * 当前页码
	 */
	private int page = 1;
	

	/**
	 * 当前记录
	 */
	private int pageSize = 10;

	private String resultInfo;

	private int recordCount;

	private int pageCount;
	
	
	//以下为dataTable插件自带分页       iTotalRecords   iTotalDisplayRecords
	private int iDisplayStart = 0;
	private int iDisplayLength = 10;
	private String sEcho;
	private String sSearch;
	
	//jqGrid自带分页插件
	private int rows;	//每页多少条数据
	private int total;	//总共多少页
	private int records;//总共多少条
	private String oper;	//jqGrid自带的编辑功能
	private String id;
    //用于排序的列名  
    private String sidx;  
    //排序的方式desc/asc  
    private String sord;  
    //是否是搜索请求  
    private boolean search;  
    //已经发送的请求的次数  
    private String nd;
    //查询过滤条件
    private String filters;
    
    
    //jqgrid treegrid参数
    private String nodeid;	//节点ID
    private String parentId;//父节点ID
	
	
	public String getFilters() {
		return filters;
	}

	public void setFilters(String filters) {
		this.filters = filters;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public String getNodeid() {
		return nodeid;
	}

	public void setNodeid(String nodeid) {
		this.nodeid = nodeid;
	}

	public String getSidx() {
		return sidx;
	}

	public void setSidx(String sidx) {
		this.sidx = sidx;
	}

	public String getSord() {
		return sord;
	}

	public void setSord(String sord) {
		this.sord = sord;
	}

	public boolean isSearch() {
		return search;
	}

	public void setSearch(boolean search) {
		this.search = search;
	}

	public String getNd() {
		return nd;
	}

	public void setNd(String nd) {
		this.nd = nd;
	}

	public boolean isEdit(){
		if ("edit".equals(this.oper)) {
			return true;
		}
		return false;
	}
	
	public boolean isDelete(){
		if ("del".equals(this.oper)) {
			return true;
		}
		return false;
	}
	
	public boolean isAdd(){
		if ("add".equals(this.oper)) {
			return true;
		}
		return false;
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	
	public String getOper() {
		return oper;
	}

	public void setOper(String oper) {
		this.oper = oper;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
		this.pageSize = rows;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public int getRecords() {
		return records;
	}

	public void setRecords(int records) {
		this.records = records;
	}

	public String getsSearch() {
		return sSearch;
	}

	public void setsSearch(String sSearch) {
		this.sSearch = sSearch;
	}

	public String getsEcho() {
		return sEcho;
	}

	public void setsEcho(String sEcho) {
		this.sEcho = sEcho;
	}

	public int getiDisplayStart() {
		return iDisplayStart;
	}

	public void setiDisplayStart(int iDisplayStart) {
		this.page = iDisplayStart+1;
		this.iDisplayStart = iDisplayStart;
	}

	public int getiDisplayLength() {
		return iDisplayLength;
	}

	public void setiDisplayLength(int iDisplayLength) {
		this.pageSize = iDisplayLength;
		this.iDisplayLength = iDisplayLength;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public String getResultInfo() {
		return resultInfo;
	}

	public void setResultInfo(String resultInfo) {
		this.resultInfo = resultInfo;
	}

	public int getRecordCount() {
		return recordCount;
	}

	public void setRecordCount(int recordCount) {
		this.recordCount = recordCount;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}
	
	public JqGridFilter getJqGridFilter(){
		return JqGridUtils.getInstance().getJqGridFilter(filters);
	}

	/**
	 * 用于异步操作时候写出结果信息
	 */
	public void wirteInfo(Object obj, HttpServletResponse response) {
		try {
			// out.write(String.valueOf(obj));
			response.setContentType("text/html;charset=utf-8");
			response.getWriter().write(String.valueOf(obj));
			response.getWriter().flush();
			response.getWriter().close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
		}
	}
}
